package com.hczt.fire.framework.jpa.controller;

import com.hczt.fire.framework.jpa.persistence.DemoUserEntity;
import com.hczt.fire.framework.jpa.service.DemoService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author marvin.ma
 * @create 2017-09-27 6:29
 * @desc demo demo
 **/
@Api(tags = "demo controller控制器")
@RestController
public class JpaDemoController {

    @Resource
    private DemoService jpaDemoService;

    @GetMapping(value = "demo/users")
    public DemoUserEntity getUserById(@RequestParam Long id) {
        return jpaDemoService.selectById(id);
    }

    @GetMapping(value = "demo/users/query")
    public DemoUserEntity getUserByQuery(@RequestParam Long id) {
        return jpaDemoService.selectByQuery(id);
    }

    @GetMapping(value = "demo/users/all")
    public List<DemoUserEntity> getAllUsers() {
        return jpaDemoService.selectAll();
    }

    @GetMapping(value = "demo/users/conds")
    public List<DemoUserEntity> getUsers(@RequestParam(required = false) Long id,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String sex,
            @RequestParam(required = false) String type,
            @RequestParam(required = false) String address) {
        return jpaDemoService.selectByConditions(id, name, sex, type, address);
    }

    @GetMapping(value = "demo/read")
    public DemoUserEntity selectByIdInReadDataBase(@RequestParam long id) {
        return jpaDemoService.selectByIdInReadDataBase(id);
    }

}
